<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title>责任链模式</title>
</head>
<body>
</body>
</html>
<script>
    function Handler(){
        this.next = null
        this.setNext = function(hander){
            this.next = hander
        }
        this.handleRequest = function(money){

        }
    }
    
    // 采购部
    var CGBHandler = function(){}
    CGBHandler.prototype = new  Handler()
    CGBHandler.prototype.handleRequest = function (money){
       if(money<10000){
           console.log('同意')
       }else{
           console.log('金额太大了')
           if(this.next){
              console.log('采购上报')
              this.next.handleRequest(money)
           }
       }
    }
    // 总经理
    var  ZJLHandler = function(){}
    ZJLHandler.prototype = new  Handler()
    ZJLHandler.prototype.handleRequest = function(money){
       if(money<100000){
          console.log('总经理同意')
       }else{
          console.log('金额太大了')
          if(this.next){
              console.log('总经理上报')
              this.next.handleRequest(money)
          }
       }
    }

    // 董事长
    var DSZHandler = function(){}
    DSZHandler.prototype.handleRequest = function(money){
        if(money>=100000){
          console.log('10万以上,董事长同意')
        }
    }

    function Client(money) {
        var cgb = new CGBHandler()
        var zjl = new ZJLHandler()
        var dsz = new DSZHandler()
        console.log(cgb,zjl)
        cgb.setNext(zjl)
        zjl.setNext(dsz)

        cgb.handleRequest(money)
    }
    Client(1000) 
</script>

